{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'snapshots'|trans }} - {{ snapshot.name }} - {{ 'failures'|trans }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'snapshots'|trans, 'link': {'url': path('snapshots')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': snapshot.name, 'badge': {'title': snapshot.state|trans, 'context': snapshot.state}}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/snapshot/snapshot_read_tabs.html.twig' with {'active': 'failures'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'failures'|trans, 'badge': {'title': snapshot.failures|length}}) }}

            {% if 0 < snapshot.failures|length %}
                {% embed 'Embed/table_embed.html.twig' %}
                    {% import 'Import/app_import.html.twig' as appImport %}

                    {% block thead %}
                        <tr>
                            <th>
                                {{ 'index'|trans }}
                            </th>
                            <th>
                                {{ 'shard'|trans }}
                            </th>
                            <th>
                                {{ 'reason'|trans }}
                            </th>
                            <th>
                                {{ 'node'|trans }}
                            </th>
                            <th>
                                {{ 'status'|trans }}
                            </th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for failure in snapshot.failures %}
                            <tr>
                                <td>
                                    {% if is_granted('INDICES_LIST', 'index') %}
                                        <a class="{{ theme_link_secondary }}" href="{{ path('indices_read', {'index': failure['index']}) }}">{{ failure['index'] }}</a>
                                    {% else %}
                                        {{ failure['index'] }}
                                    {% endif %}
                                </td>
                                <td>
                                    {{ failure['shard_id'] }}
                                </td>
                                <td>
                                    {{ failure['reason'] }}
                                </td>
                                <td>
                                    {% if nodes[failure['node_id']] is defined %}
                                        {% if is_granted('NODES_LIST', 'node') %}
                                            <a class="{{ theme_link_secondary }}" href="{{ path('nodes_read', {'node': nodes[failure['node_id']]}) }}">{{ nodes[failure['node_id']] }}</a>
                                        {% else %}
                                            {{ nodes[failure['node_id']] }}
                                        {% endif %}
                                        {% if master_node == nodes[failure['node_id']] %}{{ appImport.badge({'title': 'master'|trans, 'context': 'master_node'}) }}{% endif %}
                                    {% else %}
                                        {{ failure['node_id'] }}
                                    {% endif %}
                                </td>
                                <td>
                                    {{ failure['status'] }}
                                </td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}
